package com.tjetc.vo;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class Result<T> {
    private int code;
    private String msg;
    private T data;
    
    public static <T> Result<T> ok(){
        return new Result<T>().setCode(200).setMsg("操作成功");
    }
    
    public static <T> Result<T> ok(T data){
        return new Result<T>().setCode(200).setMsg("操作成功").setData(data);
    }
    
    public static <T> Result<T> success(T data){
        return new Result<T>().setCode(200).setMsg("操作成功").setData(data);
    }
    
    public static <T> Result<T> fail(){
        return new Result<T>().setCode(500).setMsg("操作失败");
    }
    
    public static <T> Result<T> fail(String msg){
        return new Result<T>().setCode(500).setMsg(msg);
    }
    
    public static <T> Result<T> error(String msg){
        return new Result<T>().setCode(500).setMsg(msg);
    }
    
    public static <T> Result<T> error(int code, String msg){
        return new Result<T>().setCode(code).setMsg(msg);
    }
}
